package com.situ.springbootenable;

import com.situ.springbootenableother.config.EnableUser;
import com.situ.springbootenableother.config.MyImportBeanDefinitionRegistrar;
import com.situ.springbootenableother.config.MyImportSelector;
import com.situ.springbootenableother.config.UserConfig;
import com.situ.springbootenableother.pojo.Role;
import com.situ.springbootenableother.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import redis.clients.jedis.Jedis;

import java.util.Map;

@SpringBootApplication
//@ComponentScan("com.situ.springbootenableother")
//@Import(UserConfig.class)
//@EnableUser
//@Import(User.class)
//@Import(MyImportSelector.class)
//@Import(MyImportBeanDefinitionRegistrar.class)
public class SpringbootEnableApplication {
    /*@Autowired
    private User user;*/

    //@Autowired
    //private Jedis jedis;

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(SpringbootEnableApplication.class, args);

        /*Object user = context.getBean("user");
        System.out.println(user);*/

        // 默认的名字不是user，所以根据类型获取
       /* User user = context.getBean(User.class);
        System.out.println(user);
        Map<String, User> map = context.getBeansOfType(User.class);*/
        // 名字是包名+类名
        // {com.situ.springbootenableother.pojo.User=com.situ.springbootenableother.pojo.User@3ed242a4}
        /*System.out.println(map);

        Role role = (Role) context.getBean(Role.class);
        System.out.println(role);*/

        Jedis jedis = (Jedis) context.getBean("jedis");
        System.out.println(jedis);

        jedis.set("study", "SpringBoot1");
        String value = jedis.get("study");
        System.out.println(value);
    }

}
